package com.finance.system.configure.mvc;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.deser.std.StringDeserializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalDateTime;

@Component
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
    @Autowired
    private Converter stringToLocalDateTimeConverter ;
    @Override
    public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String result = StringDeserializer.instance.deserialize(jsonParser, deserializationContext);
        return (LocalDateTime)stringToLocalDateTimeConverter.convert(result);
    }
}
